<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="关键字/id/主题标题" style="width: 200px;" class="filter-item"
        @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.order" placeholder="排序规则" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in order" :key="index" :label="item" :value="index" />
      </el-select>
      <el-select v-model="listQuery.hot" placeholder="根据精华" clearable style="width: 150px" class="filter-item">
        <el-option label="不是精华" :value="0" />
        <el-option label="只看精华" :value="1" />
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
      <el-alert v-if="add_show" :title="'当前小组名称: '+ group_name + ''" type="success" description="如需查看所有主题,请从新点击主题列表"
        show-icon>
      </el-alert>
    </div>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员昵称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员手机号码" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主题状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">正常</span>
          <span v-if="scope.row.status == 1">禁止回复</span>
        </template>
      </el-table-column>
      <el-table-column label="是否精华" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.hot == 0">不是</span>
          <span v-if="scope.row.hot == 1" style="color: red;">精华</span>
        </template>
      </el-table-column>
      <el-table-column label="主题标题" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="题目内容" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.content }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属小组" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.group_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="点赞" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_like }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收藏数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_collect }}</span>
        </template>
      </el-table-column>
      <el-table-column label="评论数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_comment }}</span>
        </template>
      </el-table-column>

      <el-table-column label="举报数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_report }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加日期" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.create_time) }}
        </template>
      </el-table-column>
      <el-table-column label="最后回复时间" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.update_time) }}
        </template>
      </el-table-column>

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <div>
            <span v-permission="['/library/answerEdit']">
              <el-button size="small" type="primary" @click="del(scope.row)">删 除</el-button>
              <el-button size="small" type="primary" @click="comment_list(scope.row)">评 论</el-button>
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />


  </div>
</template>

<script>
  import {
    themeList,
    themeDel
  } from '@/api/group';
  import {
    addressList
  } from '@/api/config';
  import waves from '@/directive/waves';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import imageUpload from '@/components/Upload/image';

  export default {
    components: {
      Pagination,
      imageUpload
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          cate_id: null,
          limit: 20,
        },
        item: {},
        order: {
          number_like: '好评数',
          number_comment: '评论数',
          number_collect: '收藏数',
          number_report: '举报数',
          id: '最新',
        },
        show: false,
        buyShow: false,
        buyList: {},
        buyTotal: 0,
        buyQuery: {
          page: 1,
          limit: 20,
          type: 1
        },
      };
    },
    created() {
      if (this.$route.params.id) {
        this.listQuery.group_id = this.$route.params.id
        this.add_show = true
      }
      if (this.$route.params.name) {
        this.group_name = this.$route.params.name
      }
      this.getList()
    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t)
      },

      comment_list(item) {
        this.$router.push({
          name: 'group/commentList',
          params: {
            id: item.id,
            type: 1,
            title: item.title
          }
        })
      },

      del(item) {
        this.$confirm('确认删除该主题?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log(111);
          themeDel({
            id: item.id
          }).then(res => {
            if (res.code == 20000) {
              this.$message({
                type: 'success',
                message: res.msg
              });
              this.show = false;
              this.getList()
            }
          })
        }).catch(() => {})
      },
      getList() {
        this.listLoading = true;
        themeList(this.listQuery).then(res => {
          this.list = res.data.data;
          this.total = res.data.total;
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },

    }
  };
</script>
